/**      
 * @file		conversion.cpp
 * @description		This sample demonstrates operator overloading and automatic
 *			type conversion.
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		2.0
 */
#include <iostream>
using namespace std;

/**
 * Represents a circle
 */
class Circle {
public:
	/**
	 * Adds the radius of two circles and creates a new circle with the
	 * result of the addition.
	 * @param aCircle1 the left hand side circle
	 * @param aCircle2 the right hand side circle
	 * @return a new Circle with circle1's radius added to circle2's
	 */
	friend Circle operator +(const Circle& aCircle, const Circle& aCircle2);

	/**
	 * Subtracts the radius of two circles and creates a new circle with the
	 * result of the subtraction.
	 * @param aCircle1 the left hand side circle
	 * @param aCircle2 the right hand side circle
	 * @return a new Circle with circle2's radius subtracted from circle1's
	 */
	friend Circle operator -(const Circle& aCircle, const Circle& aCircle2);

	/**
	 * Adds the radius of two circles and creates a new circle with the
	 * result of the addition.
	 * @param aCircle1 the left hand side circle
	 * @param aCircle2 the right hand side circle
	 * @return a new Circle with radius of circle1's radius added to circle2's
	 */
	friend bool operator ==(const Circle& aCircle, const Circle& aCircle2);

	/**
	 * Default constructor sets the circle's radius to 1
	 * @return a new Circle with the radius 1
	 */
	Circle();

	/**
	 * Constructor sets the circles radius.
	 * @param aRadius set the new circle's radius to aRadius
	 *			if aRadius is <= 0, returns a circle with a 
	 *			radius of 1
	 * @return a new circle with a radius of aRadius
	 */
	Circle(double aRadius);

	/**
	 * Returns the radius of the circle
	 * @return the radius of the circle
	 */
	double getRadius() const;

	/**
	 * Sets the radius of the circle
	 * @param aRadius the new radius of the circle
	 *			if aRadius is <= 0, the circle's radius
	 *			is set to 1
	 */
	void setRadius(double aRadius);

private:
	double mRadius;
};

/**
 * @return zero if the application executes successfully
 */
int main() {
	Circle circle1(24.0);
	cout << "Circle circle1(24.0);\n";
	
	cout << "Adding circle1 = circle1 + 10.0\n";
	// What happens here?
	// The double 10.0 get promoted to a circle.
	// This occurs because there is a constructor
	// that takes a double and creates a circle
	// without the constructor, this code will not 
	// work
	circle1 = circle1 + 10.0;

	cout << "Circle1's radius is " << circle1.getRadius() << endl;
	cout << endl;

	cout << "Subtracting circle1 = circle1 - 10.0\n";
	circle1 = circle1 - 10.0;

	cout << "Circle1's radius is " << circle1.getRadius() << endl;
	cout << endl;

	cout << "Is (circle1 == 10.0) = ";
	if(circle1 == 10.0)
		cout << "true";
	else 
		cout << "false";
	cout << endl;

	return 0;
}

/*
 * Friends of Circle
 */
Circle operator +(const Circle& aCircle, const Circle& aCircle2) {
	return Circle(aCircle.mRadius+aCircle2.mRadius);
}

Circle operator -(const Circle& aCircle, const Circle& aCircle2) {
	return Circle(aCircle.mRadius-aCircle2.mRadius);
}

bool operator ==(const Circle& aCircle, const Circle& aCircle2) {
	return (aCircle.mRadius == aCircle2.mRadius);
}

/*
 * Members of a circle
 */
Circle::Circle() {
	mRadius = 1;
}

/*
 * This constructor is needed for the auto type conversion
 */
Circle::Circle(double aRadius) : mRadius(aRadius) {
	if(aRadius <= 0)
		mRadius = 1;
}

double Circle::getRadius() const {
	return mRadius;
}

void Circle::setRadius(double aRadius) {
	mRadius = aRadius;
}

